/**
 * @param {number[]} nums
 * @param {number} k
 * @return {number}
 */
var longestOnes = function (nums, k) {
    let left = 0
    let max = 0
    let zeroCount = 0
    for (let right = 0; right < nums.length; right++) {
        if (nums[right] === 0) {
            zeroCount++
        }
        while (zeroCount > k) {
            if (nums[left] === 0) {
                zeroCount--
            }
            left++
        }
        max = Math.max(max, right - left + 1)
    }
    return max
};
console.log(longestOnes([1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0], 2));
